package phantrang;

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;

import form.DSJ_XuatHang;

import trangchu.UtilDelegate;

public class PT_ThuTien {
	public Vector<DSJ_XuatHang> getListThuTien(Integer soTrang) throws SQLException
    {
            Vector<DSJ_XuatHang> result = new Vector<DSJ_XuatHang>();
            Connection con =UtilDelegate.getConnection();
            try
            {
                    CallableStatement cst = con.prepareCall("{call DanhSach_KetThucGDBanHang(?)}");
//					System.out.println(getsoDoiTac());
                    /*
					if (getsoDoiTac() < soTrang*25||soTrang*25<=0) {
                    	cst.setInt(1, 0);
					}else cst.setInt(1, soTrang);
                    */
					cst.setInt(1, soTrang);
                    ResultSet rs =  cst.executeQuery();

                    while(rs.next())
                    {
                    	DSJ_XuatHang varmuahang = new DSJ_XuatHang();
                    	varmuahang.setID_KhachHang(rs.getString("ID_KhachHang"));
                    	varmuahang.setTenKH(rs.getString("TenKH"));
                    	varmuahang.setChungTu(rs.getString("ChungTu"));
                    	varmuahang.setNgay(rs.getString("Ngay"));
                    	varmuahang.setTongThanhToan(rs.getString("TongThanhToan"));
                    	varmuahang.setDaTra(rs.getString("DaTra"));
                    	varmuahang.setConLai(rs.getString("ConLai"));
                    	varmuahang.setGhiChu(rs.getString("GhiChu"));
                    	varmuahang.setLoaiChungTu(rs.getString("LoaiChungTu"));
                        
                        result.add(varmuahang);
                    }

            }
            catch (Exception e)
            {
                    e.printStackTrace();
                    result = null;
            }
            finally
            {
                    UtilDelegate.closeConnection(con);	
                    return result;
            }
    }
    public Integer getsoThuTien() throws SQLException
    {
    		Integer result = null;
    		Connection con =UtilDelegate.getConnection();
            try
            {
                    
                    CallableStatement soLuongRecod = con.prepareCall("{call SoLuong_KetThucGDBanHang()}");
                    ResultSet rs1 =  soLuongRecod.executeQuery();
					rs1.next();
//					System.out.println(rs1.getInt(1));
					result = rs1.getInt(1);
            }
            catch (Exception e)
            {
                    e.printStackTrace();
                    result = null;
            }
            finally
            {
                    UtilDelegate.closeConnection(con);	
                    return result;
            }
    }
}
